package ui.views.property;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ui.control.SearchTextComposite;
import dao.EgnRstScenarioId;

public class BindTestSection extends AbstractPropertySection {
	private final static Logger logger = LoggerFactory.getLogger(BindTestSection.class);
	private Text labelText;
	private EgnRstScenarioId sceId;
	private SearchTextComposite swtComp;
	
	// private ModifyListener listener = new ModifyListener() {
	//
	// public void modifyText(ModifyEvent arg0) {
	// ButtonElementProperties properties = (ButtonElementProperties)
	// buttonElement
	// .getAdapter(IPropertySource.class);
	// properties.setPropertyValue(ButtonElementProperties.PROPERTY_TEXT,
	// labelText.getText());
	// }
	// };
	public BindTestSection(){
	}
	
	
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
//		super.setInput(part, selection);
		logger.debug("Test Binding0:{}", selection.toString());
		Object input = ((IStructuredSelection) selection).getFirstElement();
		logger.debug("Test Binding11:{}", input.toString());
		this.sceId = (EgnRstScenarioId) input;
		logger.debug("Test Binding:{},{}", sceId.getSceId(), sceId.toString());
		bindValues();
	}

	@Override
	public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);
		swtComp = new SearchTextComposite(parent,SWT.NONE);


//		bindValues();
		
	}
	@Override
	public void refresh() {
	}
	

	private void bindValues() {
		DataBindingContext bindingContext = new DataBindingContext();
		
		IObservableValue myModel = PojoProperties.value(EgnRstScenarioId.class,
				"sceId").observe(sceId);
		IObservableValue myWidget = WidgetProperties.text(SWT.Modify).observe(
				swtComp.getSearchText());
		bindingContext.bindValue(myWidget, myModel);
		logger.debug("TestBinding1");
	}
}
